package com.watchmen.mini.api;

import com.watchmen.mini.common.config.Global;
import com.watchmen.mini.common.utils.ErrorMsg;
import com.watchmen.mini.common.utils.RedisUtil;
import com.watchmen.mini.common.utils.Result;
import com.watchmen.mini.common.web.BaseApiController;
import com.watchmen.mini.modules.sys.entity.User;
import com.watchmen.mini.modules.sys.interceptor.Constants;
import com.watchmen.mini.modules.sys.utils.UserUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Title: TestApi
 * @Description:
 * @Author Gapenne
 * @Version 2019/4/2 11:22
 */
@Api(tags = "测试模块")
@RestController
@RequestMapping("${webPath}/test/")
public class TestApi extends BaseApiController {
    @Autowired
    private RedisUtil redisUtil;

    @ApiOperation(value = "测试接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "name", value = "姓名", required = false, dataType = "String")})
    @ApiResponses(value = {@ApiResponse(code = 500, message = "server error")})
    @RequestMapping(value = "getUser", method = {RequestMethod.GET})
    public Result getUser(@RequestParam(required=false)String name){
        try{
            boolean f = redisUtil.set("test_kkey","aaaaaaaaaaaaaaaa", Constants.TOKEN_EXPIRES_MIN);
            System.out.println(f);
            Long expire = redisUtil.getExpire("test_kkey");
            User user = UserUtils.getByLoginName("thinkgem");
            Result result = new Result();
            result.setData(user);
            result.setExpire(expire);
            return result;
        }catch (Exception e){
            return new Result(ErrorMsg.SYSTEM_ERROR);
        }

    }



    @ApiOperation(value = "测试接口2")
    @ApiResponses(value = {@ApiResponse(code = 500, message = "server error")})
    @RequestMapping(value = "test", method = {RequestMethod.GET})
    public Result test(){
        User user = UserUtils.getByLoginName("thinkgem");
        Result result = new Result();
        result.setData(user);
        return result;
    }

}
